package com.banciyuan.bcywebview.utils.anim;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.LinearInterpolator;

/**
 * Created by squall on 2017/3/15.
 */

public class TimelineNoticeAnimation {

    public static void setAnimation(View view, int Y, int orginY) {
        AnimatorSet show = new AnimatorSet();
        AnimatorSet dismiss = new AnimatorSet();

        ValueAnimator translationY = ObjectAnimator.ofFloat(view, "translationY", Y);
        translationY.setInterpolator(new AccelerateDecelerateInterpolator());

        ValueAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f);
        alpha.setInterpolator(new LinearInterpolator());
        show.setDuration(400);
        show.play(alpha).with(translationY);

        ValueAnimator alpha2 = ObjectAnimator.ofFloat(view, "alpha", 0f);
        alpha.setInterpolator(new LinearInterpolator());

        ValueAnimator translationY2 = ObjectAnimator.ofFloat(view, "translationY", Y - orginY);
        translationY2.setInterpolator(new AccelerateDecelerateInterpolator());
        dismiss.setDuration(400);
        dismiss.setStartDelay(1000);
        dismiss.play(alpha2).with(translationY2);

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(show).before(dismiss);
        animatorSet.start();
    }

}
